<?php 

/**
 * sort complex array
 * usort($array, 'function_name');
 */

function ac_sort_by_date($a, $b) {
    if (! $a->date|| ! $b->date) {
        return true;
    }
    
    $bg1 = explode('-', (string) $a->date);
    $bg2 = explode('-', (string) $b->date);
    
    $s1 = mktime(0, 0, 0, $bg1[0], $bg1[1], $bg1[2]);
    $s2 = mktime(0, 0, 0, $bg2[0], $bg2[1], $bg2[2]);
    
    return $s1 > $s2;
}

function ac_sort_by_alpha($a, $b) {
    $s1 = str_replace(' ', '', (string) $a->name);
    $s2 = str_replace(' ', '', (string) $b->name);
    return strcasecmp($s1 , $s2);
}

/************************************************************/



/**
 * Sort simple array, ASC
 * asort($array)
 */
$array_asort = array ( 5, 3, 1, 6, 2 );
asort( $array_asort );

/************************************************************/


/**
 * 
 * arsort($array, $sorting_type)
 *  0 = SORT_REGULAR - Default. Compare items normally (don't change types)
    1 = SORT_NUMERIC - Compare items numerically
    2 = SORT_STRING - Compare items as strings
    3 = SORT_LOCALE_STRING - Compare items as strings, based on current locale
    4 = SORT_NATURAL - Compare items as strings using natural ordering
    5 = SORT_FLAG_CASE -
 */
$array_arsort = array ( 'c', 'a', 'f', 'g', 'k' );
arsort( $array_arsort, 2 );

/************************************************************/

